﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
       RevSerialPort rsp;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Focus();
            try
            {
                //如果不是默认的COM1端口，这里需要传入端口号
                //rsp = new RevSerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
                rsp = new RevSerialPort();
                rsp.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (rsp != null)
                rsp.Stop();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
         
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

          
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                label1.Text = textBox1.Text;
                textBox1.Text = "";
            }
         
        }
    }

    
}
